<?php
namespace api\modules\merchant\controllers\customer;

use backend\widgets\provinces\Provinces;
use Yii;
use api\modules\merchant\models\ResetPasswordForm;
use yii\data\Pagination;
use yii\web\NotFoundHttpException;
use api\controllers\OnAuthController;
use common\enums\StatusEnum;
use common\helpers\ResultDataHelper;
use yii\data\ActiveDataProvider;


/**
 * 客户接口
 *
 * Class InfoController
 * @package api\modules\merchant\controllers\store
 * @property \yii\db\ActiveRecord $modelClass
 * @author tjj
 */
class InfoController extends OnAuthController
{
    public $modelClass = 'common\models\member\MemberInfo';

    /**
     * 客户列表
     * @return mixed|ActiveDataProvider
     * @throws NotFoundHttpException
     */
    public function actionIndex()
    {
        $request = Yii::$app->request;
        $store_id = $request->get('store_id')??0;

        if(!$store_id)
            return ResultDataHelper::api(422, '商铺id不能为空');

        $this->checkStore($store_id);

        $query = $this->modelClass::find()
            ->where(['store_id'=>$store_id])
            ->select(['id','username','nickname','realname','head_portrait','gender','qq','email','user_money','accumulate_money','frozen_money','user_integral','visit_count','mobile','last_time','last_ip','status','created_at','updated_at'])
            ->asArray();

        $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => $this->pageSize]);

        $models = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();

        return [
            'models'=>$models,
            'pgages'=>[
                'page'=> intval($request->get('page'))??0,
                'page_size'=> intval($this->pageSize),
                'total_count'=> intval($pages->totalCount),
            ]
        ];
    }

    /**
     * 权限验证
     *
     * @param string $action 当前的方法
     * @param null $model 当前的模型类
     * @param array $params $_GET变量
     * @throws \yii\web\BadRequestHttpException
     */
    public function checkAccess($action, $model = null, $params = [])
    {
        // 方法名称
//        if (in_array($action, ['delete', 'index']))
//        {
//            throw new \yii\web\BadRequestHttpException('权限不足');
//        }
    }
}
